package org.zsl.ssm.mapper.wrapper;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.zsl.ssm.mapper.UserMapper;
import org.zsl.ssm.model.User;
import org.zsl.ssm.util.MybatisFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 *
 *  把UserMapperWrapper 注册到 spring 容器中
 *     有几种方式？
 * */

public class UserMapperWrapper implements UserMapper {


    @Override
    public List<User> selectAll() throws IOException {

        List<User>  users = new ArrayList<>();

        SqlSession session = MybatisFactory.getSession();

        UserMapper userMapper=   session.getMapper(UserMapper.class);

        users =  userMapper.selectAll();
        session.close();
        return users;
    }

    @Override
    public int exists(User user) {
        return 0;
    }
}
